<?php
class CheckSession extends Zend_Controller_Action_Helper_Abstract{
	private $auth_controllers = array('index','session','error');
	function init(){
		//este init se ejecuta justo antes del init de los controllers
		$redirect = Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
		$controller = strtolower($this->getRequest()->getControllerName());
		$action 	   = strtolower($this->getRequest()->getActionName());
		$module 	   = strtolower($this->getRequest()->getModuleName());
		
		
		$valid_user = false;
		
		if(!$_SESSION) session_start();
		
		if($_SESSION['user']){
			$user = $_SESSION['user'];
			$valid_user = true;
		}
				
		if(!$valid_user && !in_array($controller,$this->auth_controllers)){
			$redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
			$redirector->gotoUrl('/session/index');
		}
	}
}
